from search import search
from bs4 import BeautifulSoup
from connect import *

def getSoup(data):
    soup = BeautifulSoup(data, 'html.parser')
    return soup

def searchListMsg(soup):
    l = soup.find_all(attrs={'class': 'image-item'})
    url = 'http://www.pixiv.net'
    msg = []
    for item in l:
        dic = {}
        dic['url'] = url + item.contents[0]['href']
        dic['title'] = item.contents[1].h1.string
        dic['author'] = item.contents[2].string
        msg.append(dic)
        if len(item.contents) == 4:
            dic['count'] = int(item.ul.li.a.contents[1])
    return msg

if __name__ == '__main__':
    data = search('枝垂ほたる')
    soup = getSoup(data)
    msg = searchListMsg(soup)
    for item in msg:
        print(item)